/**
	Constructs a 

	@author Francis Villanueva
	@version 2006-10-17
	@copyright (c) 2006 The Chopping Block, Inc.. All rights reserved.

	@usage

	- Activate with:
	<code>

	</code>

*/

import mx.utils.Delegate;
import timber.ui.*;
import com.mosesSupposes.fuse.*;
import Classes.*;

class VideoPlayerView {
		
	private var controller:Object;
	private var view:Object;

	private var rootMC:MovieClip;
	private var player_mc:MovieClip;
	private var controls_mc:MovieClip;
	private var options_mc:MovieClip;
	private var playlist_mc:MovieClip;
	private var embedBox:MovieClip;
	private var prefBox:MovieClip;
	private var bigPlayBox:MovieClip;
	private var logo_mc:MovieClip;
	private var lastSpeedButtonClicked:MovieClip;
	private var lastPLEntryClicked:MovieClip;
	private var videoAdHolder:MovieClip;
	private var fullScreenBtn:MovieClip;
	private var toolTip:ToolTipController;
	private var toolTipTimer:Number;
	private var videoWidth:Number;
	private var videoHeight:Number;
	private var layout:String;

// ===========================================================
// - CONSTRUCTOR 
// ===========================================================
	function VideoPlayerView(controller:Object, rootMC:MovieClip) {
		//trace("\t VIEW VideoPlayerView");
		this.rootMC = rootMC;
		this.controller = controller;
		//this.view = this;
		this.videoAdHolder = rootMC.videoAdHolder;
		
		//set up zigo
		ZigoEngine.simpleSetup(Shortcuts, PennerEasing);
		
		//set up ToolTip Object
		// create our singleton instance
		toolTip = ToolTipController.getInstance();
		// if you dont supply a second argument, the ToolTipController uses the default ToolTipDefault
		ToolTipController.init(rootMC, new ToolTipFutureView());
		// specify the horozontal offset in pixels for the tooltip relative to the mouse
		ToolTipController.setOffsetX(8);
		// specify the vertical offset in pixels for the tooltip relative to the mouse
		ToolTipController.setOffsetY(4);
	}
	
// ===========================================================
// - SETUP FUNCTIONS 
// ===========================================================	

	//sets colors based from config.xml file
	private function tint(tintColor, textureAmount, targetClip:MovieClip, isShadow:Boolean):Void {
		////trace("\t VIEW tint");
		if(tintColor != undefined) {
			var tintColor = "0x"+tintColor; 
			var r = tintColor >> 16;
			var g = tintColor >> 8 & 0x00FF;
			var b = tintColor & 0x0000FF;
			if(isShadow) {
				var shadowAmt = 50;
				r = Math.max((r-= shadowAmt),0);
				g = Math.max((g-= shadowAmt),0);
				b = Math.max((b-= shadowAmt),0);
			}
			var tintColorObject = {ra:textureAmount, rb:r, ga:textureAmount, gb:g, ba:textureAmount, bb:b, aa:100, ab:0};
			var c = new Color(targetClip);
			c.setTransform(tintColorObject);
		}
	}

// ===========================================================
// - ACCESSORS
// ===========================================================

	function getPlayistMC() { return playlist_mc; }

// ===========================================================
// - DISPLAY FUNCTIONS 
// ===========================================================	

	private function centerVideo() {
		//trace("\t VIEW centerVideo");
		//get new height based on aspect ratio and the width of the video at the right size
		var trueVideoHeight = (player_mc.metadata.height * videoWidth) / player_mc.metadata.width;
		//player_mc.skin_mc._visible = false;
		//set new video size
		player_mc.setSize(videoWidth, videoHeight);
		//center video vertically
		var topBuffer = Math.floor((videoHeight - trueVideoHeight)/2);
		player_mc._y = player_mc.originY + topBuffer;
	}
	
	private function updateTimeDisplay(eventObject:Object) {
		////trace("\t VIEW eventObject.state "+eventObject.state);
		if(player_mc.buffering || eventObject.state == "loading"){
		   	////trace("\t VIEW buffering");
			var timeDisplay = "Buffering...";
			//also hide the bigButton if it's there.
			hideBigButton();
			togglePlayStopPause("disabled");
		} else {
			////trace("\t VIEW getting time");
			if(layout == "small") {
				var timeDisplay = convertTime(player_mc.playheadTime) + "<font color='#484848'> / "+convertTime(player_mc.totalTime)+"</font>";
			} else {
				var timeDisplay = convertTime(player_mc.playheadTime) + "<font color='#B2B2B2'> / "+convertTime(player_mc.totalTime)+"</font>";				
			}

		}
		//update textBox
		rootMC.bgHolder.buttons_mc.controls.duration_txt.htmlText = timeDisplay;	
	}
	
	private function convertTime(seconds:Number):String {
		//convert seconds to minutes
		var timeString:String = "";
		if (seconds>=60) {
			var minutes:Number = Math.floor(seconds/60);
			timeString = String(minutes)+":";
			seconds -= (minutes*60);
		} else {
			timeString = "0:";
		}
		if (seconds>0) {
			if(seconds < 10) {
				timeString += "0";
			} 
			timeString += String(Math.floor(seconds));
		} else {
			timeString += "00";
		}
		return timeString;
	}
	
	public function updateTitleDisplay(titleText:String){
		//trace("\t VIEW updateTitleDisplay");
		rootMC.bgHolder.title_bar_mc.mainTitleTxt.htmlText = "<font color='#"+controller.titleFontColor+"'><b>"+titleText.toUpperCase()+"</b></font>";
	};
	
	public function loadBackground(whatFile:String){
		//trace("\t VIEW loadBackground");
		var ears = {
			onLoad: function() {
				//trace("\t VIEW Background loaded");
			}
		}
		rootMC.frame_mc.addListener(ears)
		rootMC.frame_mc.load(whatFile);
	};

	public function displayPlayer(stageWidth:Number, stageHeight:Number, autoplay:Boolean, userSkip:Boolean, fullScreenEnabled:Boolean, btnsColors:Object, plVisible:Boolean, plAlign:String){
		//trace("\t VIEW displayPlayer");
					
/*		//CREATE VIDEO PLAYER
		var videoPlayer = this.createVideoPlayer(videoXPos, videoYPos,controlsXPos, controlsYPos, layout, useSpecialMediumLayout, fullScreenEnabled, userSkip, plAlign);

		//DISPLAY LOGO/BUG IN CORNER
		this.placeLogo(videoXPos, videoYPos,videoWidth,videoHeight,50);
			
		//CREATE PLAYLIST
		if(plVisible) {
			this.createPlaylist(plXPos, plYPos, plWidth, plHeight, entryHeight, plAlign, controller.getVideos());
		} else {
			controller.getVideos();
		}
		
		//CREATE OPTIONS MENU
		options_mc = this.createOptionButtons(optionsXPos, optionsYPos,plAlign, plVisible, layout);
		
		var optionsWidth = options_mc.mockWidth;
		
		//CREATE TITLE
		this.createTitleBar(titleXPos, titleYPos, optionsWidth, innerBorderWidth,layout);
	
		return videoPlayer;		*/
		
		///////////////////////////////////////////////////////
		//CREATE VIDEO PLAYER
		///////////////////////////////////////////////////////
		
		var videoAspectRatio = 3/4;
		
		var controlsHeight = 40;
		
		//DETERMINE THE VIDEO HEIGHT AND WIDTH BASED ON PLAYLIST ALIGNMENT
		if(plAlign == "right") {
			this.videoWidth = Math.floor(stageWidth/2);
			this.videoHeight = 	stageHeight - controlsHeight;
		} else if (plAlign == "bottom") {
			this.videoWidth = stageWidth;
			this.videoHeight = 	stageWidth * videoAspectRatio;//Math.floor(stageHeight/2) - controlsHeight;			
		} else {
			this.videoWidth = stageWidth;
			this.videoHeight = stageHeight;
		}
		
		//VIDEO BACKGROUND BOX (TO EMULATE BLACK BOX FOR LETTER-BOXING WIDESCREEN VIDEOS)
		var videoBG = rootMC.attachMovie('rectangle_bg_id', 'video_bg_mc', rootMC.getNextHighestDepth());
		videoBG._width = this.videoWidth;
		videoBG._height = this.videoHeight;
		
		
		//ATTACH FLV COMPONENT
		player_mc = rootMC.attachMovie('FLVPlayback', 'flvPlayer', rootMC.getNextHighestDepth());
		
		player_mc.originY = 0;
		
		//RETURN VIDEO PLAYER BACK TO CONTROLLER
		return player_mc;
		
		///////////////////////////////////////////////////////
		//CREATE OPTIONS MENU
		///////////////////////////////////////////////////////		
		
		///////////////////////////////////////////////////////
		//CREATE PLAYLIST
		///////////////////////////////////////////////////////		
		
	};

	public function createVideoPlayer(xPos:Number, yPos:Number,controlsXPos:Number,controlsYPos:Number,layout:String, useSpecialMediumLayout:Boolean, fullScreenEnabled:Boolean, userSkip:Boolean, plAlign:String) {
		

		/*
		//get highest depth
		var depth:Number = rootMC.getNextHighestDepth();
		//create empty movieclip to load flv component in it
		var mcHolder = rootMC.createEmptyMovieClip('flvHolder', depth);
		//attach flv component
		player_mc = mcHolder.attachMovie('FLVPlayback', 'flvPlayer', 1, {_x:xPos, _y:yPos});
		player_mc.originY = yPos;
		//CONTROLS
		switch(layout) {
			case "small":
				var buttonsHolder = rootMC.bgHolder.createEmptyMovieClip('buttons_mc', rootMC.bgHolder.getNextHighestDepth())
				controls_mc = buttonsHolder.attachMovie('controls_small_id', 'controls', buttonsHolder.getNextHighestDepth());
				controls_mc._x = controlsXPos;
				controls_mc._y = controlsYPos;
				controls_mc.seekbar_mc._width = videoWidth - controls_mc.duration_txt._width - 10;
				controls_mc.bufferingBar_mc._width = videoWidth - controls_mc.duration_txt._width - 10;
				controls_mc.duration_txt._x = Math.round(controls_mc.seekbar_mc._width);
				break;
			case "full":
				var offSet = 120;
				var controlsBG = rootMC.bgHolder.attachMovie('controls_full_bg', 'controlsBG', buttonsHolder.getNextHighestDepth());
				var buttonsHolder = rootMC.bgHolder.createEmptyMovieClip('buttons_mc', rootMC.bgHolder.getNextHighestDepth())
				controls_mc = buttonsHolder.attachMovie('controls_mid_full_id', 'controls', buttonsHolder.getNextHighestDepth());
				controls_mc._x = controller.embedWidth - controls_mc._width - offSet;
				controls_mc._y = controlsYPos;
				controlsBG._x = 0;
				controlsBG._y = controlsYPos;
				controlsBG._width = controller.embedWidth;
				//hide fullscreen button
				controls_mc.btn_full_screen_mc._visible = false;
			break;
			default:
				if(useSpecialMediumLayout) {
					var buttonsHolder = rootMC.bgHolder.createEmptyMovieClip('buttons_mc', rootMC.bgHolder.getNextHighestDepth())
					controls_mc = buttonsHolder.attachMovie('controls_small_id', 'controls', buttonsHolder.getNextHighestDepth());
					controls_mc._x = controlsXPos;
					controls_mc._y = controlsYPos;
					controls_mc.seekbar_mc._width = videoWidth - controls_mc.duration_txt._width - 10;
					controls_mc.bufferingBar_mc._width = videoWidth - controls_mc.duration_txt._width - 10;
					controls_mc.duration_txt._x = Math.round(controls_mc.seekbar_mc._width);
				} else {
					var offSet = 20;
					var buttonsHolder = rootMC.bgHolder.createEmptyMovieClip('buttons_mc', rootMC.bgHolder.getNextHighestDepth())
					controls_mc = buttonsHolder.attachMovie('controls_mid_full_id', 'controls', buttonsHolder.getNextHighestDepth());
					controls_mc._x = controller.embedWidth - controls_mc._width - offSet;
					controls_mc._y = controlsYPos;
				}
			break;
		}
		
		//assign colors
		this.tint(controller.labelButtonColor, 0, controls_mc.btn_play_mc.icon_mc);
		this.tint(controller.labelButtonColor, 0, controls_mc.btn_pause_mc.icon_mc);
		this.tint(controller.labelButtonColor, 0, controls_mc.btn_stop_mc.icon_mc);
		this.tint(controller.labelButtonColor, 0, controls_mc.btn_next_mc.icon_mc);
		this.tint(controller.labelButtonColor, 0, controls_mc.btn_prev_mc.icon_mc);
		this.tint(controller.labelButtonColor, 0, controls_mc.btn_full_screen_mc.bg_mc);
		
		//re-size volume bar (max of 50px wide)
		//get width left to from left of volume bar
		var widthLeft = Math.ceil(videoWidth - controls_mc.btn_volumeBar_mc._x-2);
		//set width, maximum of 50 pixels
		var volumeWidth = Math.min(widthLeft, 50);
		controls_mc.btn_volumeBar_mc._width = volumeWidth;

		//set a -yPos for seekbar to move it out of visible area for ads
		controls_mc.seekbar_mc.hideYPos = -1000;
		controls_mc.seekbar_mc.showYPos = controls_mc.seekbar_mc._y;
		
		//Release function so if you click on video, it closes playlist
		player_mc.controller = controller;
		player_mc.onRelease = Delegate.create(this, videoClicked);
		player_mc.enabled = false;
		//assign volume, seekbar, and buffer bar buttons to player
		player_mc.volumeBar = controls_mc.btn_volumeBar_mc;
		player_mc.seekBar = controls_mc.seekbar_mc;
		player_mc.bufferingBar = controls_mc.bufferingBar_mc;
		
		//set inital state of play,stop,pause buttons
		togglePlayStopPause("disabled");
		
		//play/pause/stop buttons functionality
		controls_mc.btn_play_mc.onRelease = Delegate.create(this, playVideo);
		controls_mc.btn_pause_mc.onRelease = Delegate.create(this, pauseVideo);
		controls_mc.btn_stop_mc.onRelease = Delegate.create(this, stopVideo);
				
		//set previous and next controllers
		if(userSkip) {
			controls_mc.btn_next_mc.onRelease = Delegate.create(this, next);
			controls_mc.btn_prev_mc.onRelease = Delegate.create(this, prev);
		}
		
		//set intial state of next/prev buttons
		toggleNextButton(false);
		togglePrevButton(false);
		
		//full screen button
		fullScreenBtn = controls_mc.btn_full_screen_mc;
		
		if(fullScreenEnabled) {
			fullScreenBtn.view = this;
					
			fullScreenBtn.onRollOver = function() {
				this.view.showToolTip("Launch Full Screen");
				this.gotoAndStop(2);
			}
		
			fullScreenBtn.onRollOut = function() {
				this.view.hideToolTip();
				this.gotoAndStop(1);
			}
			
			fullScreenBtn.onRelease = Delegate.create(this, launchFullScreen);
		} else {
			fullScreenBtn._visible = false;
		}
		
		return player_mc;*/
	}

	public function createPlaylist(plXPos:Number, plYPos:Number, plWidth:Number, plHeight:Number, entryHeight:Number, plAlign:String,videoList:Object,depth:Number) {
		//trace("\t VIEW createPlaylist");
		/*
		if(depth == undefined) {
			var depth:Number = rootMC.getNextHighestDepth();
		}
		//create empty movieclip to load playlist in it
		var plHolder = rootMC.createEmptyMovieClip('plHolder', depth);
		//attach flv component
		playlist_mc = plHolder.attachMovie('playlistMC', 'playlistMC', 0, {_x:plXPos, _y:plYPos});
		//set stuff as properties in case you need to recreate it
		playlist_mc.depth = depth;
		playlist_mc.plXPos = plXPos;
		playlist_mc.plYPos = plYPos;
		playlist_mc.plWidth = plWidth;
		playlist_mc.plHeight = plHeight;
		// loop through video entries
		var array = videoList;
		var loopCount = array.length;
		var trueHeight = (loopCount*entryHeight)
		if(plHeight < trueHeight) {
			var scrollBarWidth = 10;
		} else {
			var scrollBarWidth = 0;
		}
		
		//set open and close Y Pos for playlist
		playlist_mc.playlistHolder.openYPos = 0;
		playlist_mc.playlistHolder.closedYPos = plHeight + 1 // extra 1px to prevent 1px gray line when playlist is closed;
		playlist_mc.open = false;
		
		var entryHolder = playlist_mc.playlistHolder.createEmptyMovieClip('entryHolder',playlist_mc.playlistHolder.getNextHighestDepth());
		//set playlist to close Y Pos
		if(plAlign == "above") {
			playlist_mc._alpha = 75;
			playlist_mc.playlistHolder._y = playlist_mc.playlistHolder.closedYPos;
			//create background
			//figure out background height, make taller if video is taller than trueheight of playlist
			if(trueHeight < this.videoHeight) {
				var entryHolderBG = entryHolder.attachMovie('rectangle_bg_id', 'bg_mc', 1, {_width:plWidth+scrollBarWidth,_height:this.videoHeight});			
			} else {
				var entryHolderBG = entryHolder.attachMovie('rectangle_bg_id', 'bg_mc', 1, {_width:plWidth+scrollBarWidth,_height:trueHeight});
			}
		}
		
		//set width
		if(plAlign =="above") {
			playlist_mc.mask_mc._width = plWidth+2;
		} else {
			playlist_mc.mask_mc._width = plWidth;
		}
		playlist_mc.mask_mc._height = plHeight; 
		entryHolderBG.gotoAndStop(2);
		
		var alphaArray = [45, 20];
		//var colorArray = [controller.outColor, controller.overColor];

		var runningY = 0;		
		for (var i=0;i<loopCount;i++) {
			var currEntry = array[i];
			var currEntryMC = entryHolder.attachMovie('playList_entry','entry'+i, entryHolder.getNextHighestDepth(), {_y:(runningY*entryHeight)});
			//currEntryMC.index = i;
			currEntryMC.id = currEntry.id._value;
			currEntryMC.controller = controller;
			currEntryMC.view = this;
			currEntryMC.bg_mc._width = plWidth
			currEntryMC.bg_mc._height = entryHeight;
			//colorize bg_mc
			this.tint(controller.defaultBGColor, 0, currEntryMC.bg_mc, true);
			currEntryMC.bg_mc.alphaVal = alphaArray[0];
			currEntryMC.bg_mc._alpha = alphaArray[0];
			currEntryMC.attachMovie('playlist_frame_id', 'imageHolder_mc', currEntryMC.getNextHighestDepth(), {_x:10,_y:10});
			//color image border
			this.tint(controller.outerBorderColor, 0, currEntryMC.imageHolder_mc.border_mc, true);
			//set text box size
			currEntryMC.videoTitleTxt._width = plWidth - scrollBarWidth - (3*10) - currEntryMC.imageHolder_mc._width;//width of thumbnail;
			currEntryMC.videoTitleTxt.autoSize = true;
			currEntryMC.videoTitleTxt.multiline = true;
			currEntryMC.videoTitleTxt.wordWrap = true;
			currEntryMC.videoTitleTxt.htmlText = "<font color='#"+controller.playlistFontColor+"'><u>"+currEntry.headline._value+"</font></u>";
			//load thumbnail
			currEntryMC.imageHolder_mc.load(currEntry.thumbnail._value);
			//add button functionality
			currEntryMC.onRelease = function() {
				var video = this.controller.getVideoById(this.id);
				//trace("\t VIEW playlist entry onRelease")
				this.controller.setVideo();
				this.controller.hidePlaylist();
			}
			currEntryMC.onRollOver =  function() {
				this.view.tint(controller.defaultBGColor, 0, this.bg_mc, true);
			}

			currEntryMC.onRollOut = currEntryMC.onRollOut =  function() {
				if(this != this.view.lastPLEntryClicked) {
					this.bg_mc._alpha = this.bg_mc.alphaVal;
				}
			}
			//update runningY
			runningY++;
			//reverse alphaArray for alternating colors;
			alphaArray.reverse();
		}
		
		//create gradients (disabled for now)
		//var plGradient = playlist_mc.playlistHolder.attachMovie('playlist_gradient_id', 'gradient_mc',playlist_mc.playlistHolder.getNextHighestDepth(), {_width:plWidth,_height:plHeight});
		
		//sets scrollbar (if necessary)
		if (plHeight < trueHeight) {
			var scrollBarHolder = playlist_mc.playlistHolder.createEmptyMovieClip('scrollBarHolder',playlist_mc.playlistHolder.getNextHighestDepth());
			var scrollBar = scrollBarHolder.attachMovie('Slider', 'scrollbar_mc', 1, {_x:plWidth-scrollBarWidth, _y:5});
			scrollBar.setSize(plHeight-10);
			scrollBar.setTarget(playlist_mc.playlistHolder.entryHolder);
			scrollBar.setViewSize(plHeight);
			scrollBar.back_mc._height = plHeight - 10;
		}
		//create border
		var plBorder = playlist_mc.playlistHolder.attachMovie('img_id', 'border_mc',playlist_mc.playlistHolder.getNextHighestDepth(), {_width:plWidth-1,_height:plHeight-1});
		this.tint(controller.defaultBGColor, 0, plBorder, true);

		if(videoList.length == 0 || videoList == undefined) {
			playlist_mc._visible = false;
		} else {
			playlist_mc._visible = true;
		}*/
	}
	
	public function createOptionButtons(xPos:Number, yPos:Number,plAlign:String, plVisible:Boolean, layout:String) {
		//trace("\t VIEW createOptionButtons")
		//OPTIONS MENU
		//attach option buttons
	/*	var btnRunningX = 0;
		var btnBuffer = 6;
		var depth:Number = rootMC.getNextHighestDepth();
		var btnsHolder = rootMC.createEmptyMovieClip('btnsHolder', rootMC.getNextHighestDepth());
		//attach playlist
		if(plVisible) {
			var playlist_btn = btnsHolder.attachMovie('btn_playlist_id', 'btn_playlist_mc', btnsHolder.getNextHighestDepth(), {_x:btnRunningX});
			if(plAlign == "above") {
				this.tint(controller.labelButtonColor, 0, playlist_btn);
				playlist_btn.playlist_ref = this.playlist_mc;
				playlist_btn.player_ref = this.player_mc;
				playlist_btn.onRelease = function() {
					if(this.playlist_ref.open) {
						this.playlist_ref.open = false;
						ZigoEngine.doTween(this.playlist_ref.playlistHolder, "_y", this.playlist_ref.playlistHolder.closedYPos, .75, "easeInOutExpo", 0);
						this.player_ref.enabled = false;
					} else {
						ZigoEngine.doTween(this.playlist_ref.playlistHolder, "_y", this.playlist_ref.playlistHolder.openYPos, .75, "easeInOutExpo", 0);
						this.playlist_ref.open = true;
						this.player_ref.enabled = true;
					}
				}
				btnRunningX += playlist_btn._width + btnBuffer;
			} else {
				playlist_btn._visible = false;				
			}
		} else {
			trace(" ------> playlist disabled");
		}
		//attach prefs
		var pref_btn = btnsHolder.attachMovie('btn_pref_id', 'btn_pref_mc', btnsHolder.getNextHighestDepth(), {_x:btnRunningX});
		this.tint(controller.labelButtonColor, 0, pref_btn);
		pref_btn.controller = controller;
		pref_btn.onRelease = function() {
			controller.createPreferences();
		}
		btnRunningX += pref_btn._width + btnBuffer;
		//attach embed
		var embed_btn = btnsHolder.attachMovie('btn_embed_id', 'btn_embed_mc', btnsHolder.getNextHighestDepth(), {_x:btnRunningX});
		this.tint(controller.labelButtonColor, 0, embed_btn);
		embed_btn.controller = controller;
		embed_btn.onRelease = function() {
			controller.createEmbedCode();
		}
		btnRunningX += embed_btn._width + btnBuffer;

		//set mock width to pass to title bar
		btnsHolder.mockWidth = btnRunningX;
		//if full layout, make close button
		switch(layout) {
			case "full":
				var close_btn = btnsHolder.attachMovie('btn_close_id', 'btn_close_mc', btnsHolder.getNextHighestDepth(), {_x:btnRunningX});
				this.tint(controller.labelButtonColor, 0, close_btn);
				close_btn.onRelease = function() {
					getURL("javascript:self.close()");
				}
				btnRunningX += close_btn._width + btnBuffer;
			break;
		}
		
		//set x and y
		switch(layout) {
			case "small":
				btnsHolder._x = xPos;
				btnsHolder._y = yPos//Math.round(yPos - btnsHolder._height - (btnBuffer/2));
			break;
			case "full":
				btnsHolder._x = controller.embedWidth - (xPos*2) - btnsHolder._width - btnBuffer*5;
				btnsHolder._y = Math.floor(videoHeight + (btnBuffer/2));
			break;
			default:
				var offSet = 40;
				btnsHolder._x = controller.embedWidth - (xPos*2) - btnsHolder._width - btnBuffer - offSet;
				btnsHolder._y = yPos//Math.round(yPos - btnsHolder._height - (btnBuffer/2));
			break;
		}
		
		return btnsHolder;*/
	}
	
	public function createTitleBar(xPos:Number, yPos:Number,optionsWidth:Number,borderWidth:Number,layout:String) {
		//trace("\t VIEW createTitleBar");
		/*switch(layout) {
			case "small":
				var titleBar = rootMC.bgHolder.attachMovie('titleBar_small_id', 'title_bar_mc', rootMC.bgHolder.getNextHighestDepth());
				titleBar.bg_mc._width = videoWidth+(borderWidth*2);
				titleBar.mainTitleTxt._width = videoWidth;
				titleBar.mainTitleTxt._x = borderWidth;
				titleBar._x = xPos;
				titleBar._y = yPos;
				
				//set tint on drop shadow;
				this.tint(controller.defaultBGColor, 0, titleBar.bg_mc, true);
			break;
			case "medium":
				var offset = 60;
				var titleBar = rootMC.bgHolder.attachMovie('titleBar_id', 'title_bar_mc', rootMC.bgHolder.getNextHighestDepth());
				titleBar.middle_mc._width = videoWidth - titleBar.left_mc._width - titleBar.right_mc._width - optionsWidth - offset;
				titleBar.mainTitleTxt._width = titleBar.middle_mc._width;
				titleBar.mainTitleTxt._x = titleBar.middle_mc._x;
				titleBar.right_mc._x = titleBar.left_mc._width +titleBar.middle_mc._width + titleBar.right_mc._width;
				titleBar._x = xPos;
				titleBar._y = yPos - videoHeight - titleBar._height;
			break;
		}*/
	}
	
	public function placeLogo(xPos:Number,yPos:Number,width:Number,height:Number,alpha:Number) {
		//trace("\t VIEW placeLogo");
		var logoBuffer = 10;
		//percent of video screen to set logo size too.
		var scalePercent = 10;
		var logoHolder = rootMC.createEmptyMovieClip('logoHolder', rootMC.getNextHighestDepth());
		var logo = logoHolder.attachMovie('frame_id', 'frame_mc', 1);
		var placeLogo = {
			onLoad: function() {	 
				trace  ("\t -----------> logo loaded");
				logo._alpha = alpha;
				logo._x = (xPos + width) - (logo._width + logoBuffer);
				logo._y = (yPos + height) - (logo._height + logoBuffer);
			}
		}
		logo.onRelease = Delegate.create(this, launchSiteURL);
		logo.addListener(placeLogo);
		logo.load(controller.logo);
		logo_mc = logo;
	}

	public function setVideo(video:Object) {
		//trace("\t VIEW setVideo and speed is "+controller.defaultSpeed);
		//update title display
		//trace("\t\t ----> video.headline._value "+video.headline._value)
		this.updateTitleDisplay(video.headline._value);
		/*set video based on default speed */
		var prevVideo = player_mc.contentPath;
		switch (controller.defaultSpeed) {
			case "high":
			player_mc.contentPath = video.videohigh._value;
			break;
			case "medium":
			player_mc.contentPath = video.videomedium._value;
			break;
			case "low":
			player_mc.contentPath = video.videolow._value;
			break;
			default:
			player_mc.contentPath = video.videomedium._value;
			break;
		}
	}

// ===========================================================
// - BUTTON FUNCTIONS
// ===========================================================
	
	function playVideo() {
		controller.playVideo();
	}
	
	function pauseVideo() {
		controller.pauseVideo();
	}
	
	function stopVideo(){
		controller.stopVideo();
	};
	
	function next(){
		//trace("\t VIEW next");
		controller.next();
	};
	
	function prev(){
		//trace("\t VIEW prev");
		controller.prev();
	};

	function videoClicked() {
		//trace("\t VIEW videoClicked");
		controller.videoClicked();
	}
	
	function toggleAllButtons(state:Boolean, bigButtonState:Boolean) {
		//trace("\t VIEW toggleAllButtons");
		//trace("\t\t -----------> all buttons will be set to "+state+" "+"big button will be set to "+bigButtonState);
		this.togglePrevButton(state);
		this.toggleNextButton(state);
		this.togglePLButtons(state);
		this.toggleOptionButtons(state);
		this.toggleFullScreenButton(state);
		this.toggleLogo(state);
		this.player_mc.playButton.enabled = state;
		this.player_mc.stopButton.enabled = state;
		this.player_mc.pauseButton.enabled = state;
		this.player_mc.volumeBar.enabled = state;
		this.player_mc.seekBar.enabled = state;
		this.player_mc.bufferingBar.enabled = state;
		//this.player_mc.enabled = state;
		if(this.bigPlayBox != undefined) {
			this.bigPlayBox.bigPlayBG.enabled = bigButtonState;
			this.bigPlayBox.bigPlay_btn_mc.enabled = bigButtonState;
		}
	}
	
	function togglePlaylistButton(state:Boolean) {
		//trace("\t VIEW disable playlist button");
		if(options_mc.btn_playlist_mc != undefined) {
			options_mc.btn_playlist_mc.enabled = state;
		}
	}
	
	function togglePrevButton(state:Boolean){
		//trace("\t VIEW togglePrevButton "+state);	
		controls_mc.btn_prev_mc.enabled = state;
		if(state) {
			controls_mc.btn_prev_mc._alpha = 100;
		} else {
			controls_mc.btn_prev_mc._alpha = 50;
		}
	};

	function toggleNextButton(state:Boolean){
		//trace("\t VIEW toggleNextButton "+state);
		controls_mc.btn_next_mc.enabled = state;
		if(state) {
			controls_mc.btn_next_mc._alpha = 100;
		} else {
			controls_mc.btn_next_mc._alpha = 50;
		}
	};

	function togglePlayStopPause(status:String) {
		//trace("\t VIEW togglePlayStopPause");
		trace("\t\t -------> "+status)
		switch (status) {
			case "playing":
				controls_mc.btn_play_mc.enabled = false;
				controls_mc.btn_stop_mc.enabled = true;
				controls_mc.btn_pause_mc.enabled = true;
				controls_mc.btn_play_mc._visible = false;
				controls_mc.btn_stop_mc._visible = true;
				controls_mc.btn_pause_mc._visible = true;
				controls_mc.btn_play_mc._alpha = 50;
				controls_mc.btn_stop_mc._alpha = 100;
				controls_mc.btn_pause_mc._alpha = 100;
			break;
			case "paused":
				controls_mc.btn_play_mc.enabled = true;
				controls_mc.btn_stop_mc.enabled = true;
				controls_mc.btn_pause_mc.enabled = false;
				controls_mc.btn_play_mc._visible = true;
				controls_mc.btn_stop_mc._visible = true;
				controls_mc.btn_pause_mc._visible = false;
				controls_mc.btn_play_mc._alpha = 100;
				controls_mc.btn_stop_mc._alpha = 100;
				controls_mc.btn_pause_mc._alpha = 50;
			break;
			case "stopped":
				controls_mc.btn_play_mc.enabled = true;
				controls_mc.btn_stop_mc.enabled = false;
				controls_mc.btn_pause_mc.enabled = false;
				controls_mc.btn_play_mc._visible = true;
				controls_mc.btn_stop_mc._visible = true;
				controls_mc.btn_pause_mc._visible = false;
				controls_mc.btn_play_mc._alpha = 100;
				controls_mc.btn_stop_mc._alpha = 50;
				controls_mc.btn_pause_mc._alpha = 50;
			break;
			case "disabled":
				controls_mc.btn_play_mc.enabled = false;
				controls_mc.btn_stop_mc.enabled = false;
				controls_mc.btn_pause_mc.enabled = false;
				controls_mc.btn_play_mc._visible = true;
				controls_mc.btn_stop_mc._visible = true;
				controls_mc.btn_pause_mc._visible = false;
				controls_mc.btn_play_mc._alpha = 50;
				controls_mc.btn_stop_mc._alpha = 50;
				controls_mc.btn_pause_mc._alpha = 50;
			break;
		}	
	}
	
	function togglePLButtons(state:Boolean) {
		for (var i in playlist_mc.playlistHolder.entryHolder) {
			var currItem = playlist_mc.playlistHolder.entryHolder[i];
			if(typeof currItem == "movieclip") {
				currItem.enabled = state;
			}
		}
	}

	function togglePrefButton(state:Boolean) {
		options_mc.btn_pref_mc.enabled = state;
	}

	function toggleSeekBar(state:Boolean) {
		////trace("\t VIEW toogleSeekBar set to "+state);
		//controls_mc.seekBarCover_mc._visible = !state;
		if(state) {
			//player_mc.seekBar = controls_mc.seekbar_mc;
			controls_mc.seekbar_mc._y = controls_mc.seekbar_mc.showYPos;
			//player_mc.seekBar._parent.seekBarHandle_mc._visible = state;
		} else {
			controls_mc.seekbar_mc._y = controls_mc.seekbar_mc.hideYPos;
			//player_mc.seekBar._parent.seekBarHandle_mc._visible = state;
			//player_mc.seekBar._parent.seekBarHandle_mc.removeMovieClip();
			//player_mc.seekBar = undefined;
		}
		//player_mc.seekBar._visible = state;
		//player_mc.seekBar._parent.seekBarHandle_mc._visible = state;
		//player_mc.seekBar._parent.seekBarHandle_mc.enabled = state;
	}

	function toggleOptionButtons(state:Boolean) {
		//trace("\t VIEW toggleOptionButtons");
		for (var i in options_mc) {
			var currItem = options_mc[i];
			if(typeof currItem == "movieclip") {
				currItem.enabled = state;
			}
		}
	}

	function toggleFullScreenButton(state:Boolean) {
		controls_mc.btn_full_screen_mc.enabled = state;
		if(state) {
			controls_mc.btn_full_screen_mc._alpha = 100;
		} else {
			controls_mc.btn_full_screen_mc._alpha = 50;
		}
	}

	function toggleLogo(state:Boolean) {
		logo_mc._visible = state;
	}

// ===========================================================
// - PLAYLIST FUNCTIONS
// ===========================================================	

	function selectEntry(index:Number){
		//trace("\t VIEW selectEntry");
		//reset last entry clicked/selected
		this.lastPLEntryClicked.enabled = true;
		this.lastPLEntryClicked.bg_mc._alpha = this.lastPLEntryClicked.bg_mc.alphaVal;
		//set new entry
		var currEntry = playlist_mc.playlistHolder.entryHolder["entry"+index];
		currEntry.enabled = false;
		this.tint(controller.defaultBGColor, 0, currEntry.bg_mc, true);
		this.lastPLEntryClicked = currEntry;
	};

	function hidePlaylist() {
		//trace("\t VIEW hidePlaylist");
		playlist_mc.open = false;
		playlist_mc.playlistHolder.entryHolder._y = 0;
		ZigoEngine.doTween(playlist_mc.playlistHolder, "_y", playlist_mc.playlistHolder.closedYPos, .5, "easeInOutExpo", 0);
	}

// ===========================================================
// - OPTIONS MENU AND BIG PLAY BUTTON FUNCTIONS
// ===========================================================

	function showBigButton(whatButton:String, siteURL:String) {
		//trace("\t VIEW showBigButton");
		player_mc.enabled = false;
		
		var xPos = rootMC.bgHolder.video_bg_mc._x;
		var yPos = rootMC.bgHolder.video_bg_mc._y;
		var bgHeight = rootMC.bgHolder.video_bg_mc._height;
		var bgWidth = rootMC.bgHolder.video_bg_mc._width;
		//create holder
		var depth:Number = rootMC.getNextHighestDepth();
		bigPlayBox = rootMC.createEmptyMovieClip('bigPlayHolder', depth);
		var bigPlayBG = bigPlayBox.attachMovie('rectangle_bg_id', 'bigPlayBG', bigPlayBox.getNextHighestDepth(), {_x:xPos,_y:yPos,_width:bgWidth,_height:bgHeight,_alpha:60});
		//apply onRelease event
		bigPlayBG.onRelease = function() {
			getURL(siteURL, "_blank");
		}
		if(whatButton == undefined || whatButton == "") {
			//load default play button
			var playBtn = bigPlayBox.attachMovie('bigPlay_btn_id', 'bigPlay_btn_mc', bigPlayBox.getNextHighestDepth());
			//scale button where it's no smaller than minimum nor any bigger than maximum
		 	var minSize = 20;
			var maxSize = 120;
			var percent = .25;
			var scaledWidth = bgWidth*percent;
			var oldWidth = playBtn._width;
			var minSize = Math.max(minSize, scaledWidth);
			var maxSize = Math.min(minSize, maxSize);
			playBtn._width = maxSize;
			playBtn._height = (playBtn._height*maxSize)/oldWidth;
		
			playBtn._x = (xPos + (bgWidth/2)) - (playBtn._width/2);
			playBtn._y = (yPos + (bgHeight/2)) - (playBtn._height/2);
			
		} else {
			//function for when image is finished loading
			var ears = {
				onLoad: function() {
					//scale button where it's no smaller than minimum nor any bigger than maximum
				 	var minSize = 20;
					var maxSize = 120;
					var percent = .25;
					var scaledWidth = bgWidth*percent;
					var oldWidth = playBtn._width;
					var minSize = Math.max(minSize, scaledWidth);
					var maxSize = Math.min(minSize, maxSize);
					playBtn._width = maxSize;
					playBtn._height = (playBtn._height*maxSize)/oldWidth;
					//center button because it loads from top left corner
				 	playBtn._x = (xPos + (bgWidth/2)) - (playBtn._width/2);
					playBtn._y = (yPos + (bgHeight/2)) - (playBtn._height/2);
				}
			}

			//load custom play button
			var playBtn = bigPlayBox.attachMovie('frame_id', 'play_btn_mc',bigPlayBox.getNextHighestDepth());
			//add listener
			playBtn.addListener(ears);
			//load image/swf
			playBtn.load(whatButton);
		}
		//set reference to video player
		playBtn.videoPlayer = player_mc;
		//apply onRelease event
		playBtn.onRelease = function() {
//			player_mc.play();
			this.videoPlayer.play();
		}
	}

	function hideBigButton() {
		//trace("\t VIEW hideBigButton");
		
		if(rootMC.bigPlayHolder) {
			//have to swap depths to a normal number because of getNextHighestDepth sometimes return crazy number
			rootMC.bigPlayHolder.swapDepths(1000);
			rootMC.bigPlayHolder.removeMovieClip();
		}
		//re-enabled player_mc mouse event
		//player_mc.enabled = true;
	}

	function showErrorMessage(width:Number, height:Number, msg:String) {
		//trace("\t VIEW showErrorMessage");
		var messageBox = rootMC.createEmptyMovieClip('embedBox', rootMC.getNextHighestDepth());
		var msgBG = messageBox.attachMovie('rectangle_bg_id', 'msg_bg_mc', messageBox.getNextHighestDepth());
		//set up bg size and placement, height is based on boxheight
		msgBG._width = width;
		msgBG._height = height;
		msgBG._alpha = 90;
		msgBG.controller = controller
		msgBG.onRelease = function() {
			this.controller.hideErrorMessage(this._parent);
		}
		var messageTxt =  messageBox.createTextField('messageBox_txt',  messageBox.getNextHighestDepth(), msgBG._x, msgBG._y, width-20, height-20);

		//set textbox properties
		messageTxt.autoSize = true;
		messageTxt.selectable = false;
		messageTxt.multiline = true;
		messageTxt.wordWrap = true;
		messageTxt.text = msg;
		//set up text format
		var my_fmt:TextFormat = new TextFormat();
		my_fmt.color = 0xFFFFFF;
		my_fmt.font = "Arial";
		my_fmt.size = 14;
		my_fmt.align = "center";
		//set text format to messageBox
		messageTxt.setTextFormat(my_fmt);
		
		//center messageBox
		messageTxt._x = ((width/2) - (messageTxt._width/2))
		messageTxt._y = ((height/2) - (messageTxt._height/2))-20;
	}

	function hideErrorMessage(errorMC:MovieClip){
		//trace("\t VIEW hideErrorMessage");
		errorMC.swapDepths(5000);
		errorMC.removeMovieClip();
	};

	function showEmbedCode(width:Number, height:Number, embedCodeWidth:Number, embedCodeHeight:Number,embedURL:String, videoID:String){
		//trace("\t VIEW showEmbedCode");
		embedBox = rootMC.createEmptyMovieClip('embedBox', rootMC.getNextHighestDepth());
		var embedBG = embedBox.attachMovie('rectangle_bg_id', 'msg_bg_mc', embedBox.getNextHighestDepth());
		//set up bg size and placement, height is based on boxheight
		embedBG._width = width;
		embedBG._height = height;
		embedBG._alpha = 90;
		embedBG.controller = controller;
		embedBG.onRelease = function() {
			this.controller.hideEmbedCode();
		}
		
		//msg background
		var buffer = 10;
		//attach main pref movieclip
		var msgBG = embedBox.attachMovie('optionBox_id', 'bg_mc', embedBox.getNextHighestDepth());
		//set box title text
		msgBG.optionTitle_txt.htmlText = "<b><u>Embed This Video:</u></b>"
		//set up bg size and placement, height is based on boxheight
		
		msgBG.bg_mc._width = width - (buffer*2)
		msgBG.bg_mc._height = height - (buffer*2);
		msgBG._x = ((width/2) - (msgBG._width/2));		
		
		var maxHeight = Math.min(height - (buffer*2), 150);
		var messageHolder = embedBox.createEmptyMovieClip('messageHolder', embedBox.getNextHighestDepth());
		
		var messageBox = messageHolder.createTextField('messageBox_txt', messageHolder.getNextHighestDepth(), msgBG._x+10, msgBG._y + 50, width-(buffer*4), maxHeight);

		//set textbox properties
		if(messageBox._width > 300) {
			messageBox.wordWrap = true;		
		} else {
			messageBox.wordWrap = false;
		}
		messageBox.selectable = true;
		messageBox.multiline = true;
		messageBox.autoSize = true;
		//messageBox.border = true;
		messageBox.type = "dynamic";
		
		//set Message
		var embedCode = "\n";//"Please copy the following code and paste it into your html page:\n\n";
		embedCode += '<object width="'+embedCodeWidth+'" height="'+embedCodeHeight+'">\n';
		embedCode += '<param name="movie" value="'+embedURL+videoID+'"></param>\n';
		embedCode += '<param name="wmode" value="transparent"></param>\n';
		embedCode += '<embed src="'+embedURL+videoID+'" type="application/x-shockwave-flash" wmode="transparent" width="'+embedCodeWidth+'" height="'+embedCodeHeight+'"></embed>\n';
		embedCode += '</object>';
		messageBox.text = embedCode;
		
		messageBox._width = messageBox.textWidth;
		
		//set up text format
		var my_fmt:TextFormat = new TextFormat();
		my_fmt.color = 0x010101;
		my_fmt.font = "Arial";
		my_fmt.size = 12;
		//set text format to messageBox
		messageBox.setTextFormat(my_fmt);
		//veritcal center messageBox and msgBG
		msgBG.bg_mc._height = messageBox._height + (buffer*5);
		msgBG._y = ((height/2) - (msgBG._height/2));
		messageBox._y = msgBG._y + (buffer*4)
		
		//add scrollbar
		if (messageBox._width > msgBG._width) {
			//sets scrollbar (if necessary)
				//add more space for scrollbar
				msgBG.bg_mc._height += (buffer*2);
				var scrollBarHolder = embedBox.createEmptyMovieClip('scrollBarHolder',embedBox.getNextHighestDepth());
				var scrollBar = scrollBarHolder.attachMovie('Slider', 'scrollbar_mc', 1, {_x:messageBox._x, _y:msgBG._y + msgBG.bg_mc._height - (buffer*2)});
				//var scrollBar = scrollBarHolder.attachMovie('Slider', 'scrollbar_mc', 1, {_x:100, _y:100});
				scrollBar.setSize(msgBG.bg_mc._width-(buffer*2));
				//scrollBar.setSize(100);
				scrollBar.setTarget(messageBox, "_x");
				scrollBar.setViewSize(msgBG.bg_mc._width-(buffer*2));
				scrollBar.back_mc._height = msgBG.bg_mc._width-(buffer*2);
				scrollBar._rotation = -90;
		} else {
			//re-adjust height / width based off of textbox
			msgBG.bg_mc._width = messageBox._width + (buffer*2);
			msgBG.bg_mc._height += ((messageBox._height+buffer) - msgBG.bg_mc._height)+(buffer*5);
			trace("messageBox._height "+messageBox._height);
		}
		
		//CLOSE BUTTON
		var closeBtn = msgBG.btn_close_mc;
		closeBtn._x = Math.floor(msgBG.bg_mc._width - closeBtn._width - buffer);
		closeBtn.controller = controller;
		closeBtn.view = this;
		closeBtn.onRelease = function() {
			this.controller.hideEmbedCode();
		}
		closeBtn.onRollOver = function() {
			this.view.tint(controller.highlightColor, 0, this);
		}
		
		closeBtn.onRollOut = function() {
			this.view.tint(controller.labelButtonColor, 0, this);
		}
		
		//horizontal center messageBox and msgBG
		msgBG._x = Math.round((width/2) - (msgBG.bg_mc._width/2));
		msgBG._y = Math.round((height/2) - (msgBG.bg_mc._height/2));
		messageBox._x = msgBG._x + buffer;
		trace(msgBG._x);
		messageBox._y = msgBG._y + (buffer*4);
		if(scrollBar != undefined) {
			scrollBar._x = msgBG.bg_mc._x + (buffer*2);
			//set mask
			var mask = embedBox.attachMovie('rectangle_bg_id', 'mask_mc', embedBox.getNextHighestDepth());
			mask._x = msgBG.bg_mc._x + (buffer);
			mask._y = msgBG._y + (buffer*4);
			mask._width = msgBG.bg_mc._width - (buffer);
			mask._height = msgBG.bg_mc._height;
			messageHolder.setMask(mask);
			
		}
	};
	
	function hideEmbedBox() {
		embedBox.swapDepths(5000);
		embedBox.removeMovieClip();	
	}
	
	function showPref(width:Number, height:Number, speed:String, birthMonth:Number, birthDay:Number, birthYear:Number) {
		//trace("\t VIEW showPreferences");
		prefBox = rootMC.createEmptyMovieClip('prefBox', rootMC.getNextHighestDepth());
		var embedBG = prefBox.attachMovie('rectangle_bg_id', 'msg_bg_mc', prefBox.getNextHighestDepth());
		//set up bg size and placement, height is based on boxheight
		embedBG._width = width;
		embedBG._height = height;
		embedBG._alpha = 90;
		
		//attach main pref movieclip
		var optionBox = prefBox.attachMovie('prefScreen_id', 'bg_mc', prefBox.getNextHighestDepth());
		optionBox.main_mc.optionTitle_txt.htmlText = "<b><u>Set Your Preferences</u></b>"
		
		//set x and y
		optionBox._x = (width/2) - (optionBox._width/2);
		optionBox._y = (height/2) - (optionBox._height/2);
		
		//CLOSE BUTTON
		var closeBtn = optionBox.main_mc.btn_close_mc;
		this.tint(controller.labelButtonColor, 0, closeBtn);
		closeBtn.controller = controller;
		closeBtn.view = this;
		closeBtn.onRelease = function() {
			var inputs = this._parent._parent;
			var isValidDate = this.controller.validateDate(inputs.birthMonth_txt.text, inputs.birthDay_txt.text, inputs.birthYear_txt.text);
			if(isValidDate) {
				this.controller.updatePlayer(inputs.birthMonth_txt.text, inputs.birthDay_txt.text, inputs.birthYear_txt.text);
				this.controller.hidePreferences();
			} else {
				trace("DATE NOT VALID");
				var errorBox = inputs.errorBox_txt;
				errorBox.text = "DATE IS NOT VALID.";
			}
		}
		closeBtn.onRollOver = function() {
			this.view.tint(this.controller.highlightColor, 0, this);
		}
		
		closeBtn.onRollOut = closeBtn.onReleaseOutside =function() {
			this.view.tint(this.controller.labelButtonColor, 0, this);
		}
		//CREATE LOW/MEDIUM/HIGH BUTTONS
		var speeds = ["low","medium","high"];
		var btnCount = speeds.length;
		
		for (var i=0;i<btnCount;i++) {
			var currBtn = optionBox["btn_"+speeds[i]+"_mc"];
			this.tint(controller.labelButtonColor, 0, currBtn);
			currBtn.view = this;
			currBtn.controller = controller;
			currBtn.speed = speeds[i];
			//highlight selected speed
			if(currBtn.speed == speed) {
				this.tint(controller.highlightColor,0, currBtn);
				currBtn.enabled = false;
				lastSpeedButtonClicked = currBtn;
			}
			currBtn.onRelease = function() {
				trace("SPEED IS "+this.speed);
				this.controller.setDefaultSpeed(this.speed);
				this.view.tint(this.controller.highlightColor,0, this);
				//enable and color last select button
				this.view.lastSpeedButtonClicked.enabled = true;
				this.view.tint(this.controller.labelButtonColor,0, this.view.lastSpeedButtonClicked);
				//set this button to be disabled and set as last selected
				this.enabled = false;
				this.view.lastSpeedButtonClicked = this;
			}
			currBtn.onRollOver = function() {
				this.view.tint(this.controller.highlightColor,0, this);				
			}
			
			currBtn.onRollOut = currBtn.onReleaseOutside = function() {
				if(this != this.view.lastSpeedButtonClicked) {
					this.view.tint(this.controller.labelButtonColor,0, this);
				}
			}
		}
		
		//apply functions to input boxes
		var birthday = [birthMonth,birthDay,birthYear];
		var boxes = ["birthMonth","birthDay","birthYear"];
		var boxCount = birthday.length;
		
		for (var i=0;i<boxCount;i++) {
			var currInputBox = optionBox[boxes[i]+"_txt"];
			//set textbox properties
			currInputBox.selectable = true;
			currInputBox.multiline = false;
			currInputBox.restrict = "0-9";
			//set Message
			if(birthday[i] == undefined) {
				currInputBox.text = "";
			} else {
				currInputBox.text = birthday[i];
			}
			
		}
		
		//APPLY CHANGE BUTTON FUNCTIONS
		var submitBtn = optionBox.btn_apply_mc;
		this.tint(controller.labelButtonColor,0, submitBtn);
		submitBtn.controller = controller;
		submitBtn.view = this;
		submitBtn.onRelease = function() {
			trace("SUBMIT CHANGES")
			var inputs = this._parent;
			//validate
			var isValidDate = this.controller.validateDate(inputs.birthMonth_txt.text, inputs.birthDay_txt.text, inputs.birthYear_txt.text);
			if(isValidDate) {
				this.controller.updatePlayer(inputs.birthMonth_txt.text, inputs.birthDay_txt.text, inputs.birthYear_txt.text);
				this.controller.hidePreferences();
			} else {
				trace("DATE NOT VALID");
				var errorBox = this._parent.errorBox_txt;
				errorBox.text = "DATE IS NOT VALID.";
			}
		}
		
		submitBtn.onRollOver = function() {
			this.view.tint(controller.highlightColor,0, this);
		}
		
		submitBtn.onRollOut = function() {
			this.view.tint(controller.labelButtonColor,0, this);
		}
		
	};

	function hidePrefBox() {
		prefBox.swapDepths(5000);
		prefBox.removeMovieClip();
	}

	function showToolTip(msg:String){
		//trace("\t VIEW showToolTip");
		ToolTipController.create(rootMC, "top", "center", msg);
		toolTipTimer = setInterval(this, "hideToolTip", 4000);
	};
	
	function hideToolTip(){
		//trace("\t VIEW hideToolTip");
		clearInterval(toolTipTimer);
		ToolTipController.destroy();
	};

// ===========================================================
// - LAUNCH OTHER WINDOW FUNCTIONS 
// ===========================================================	

	function launchFullScreen():Void {
		//trace("\t VIEW launchFullScreen");
		controller.launchFullScreen();
	}

	function launchSiteURL():Void{
		controller.launchSiteURL();
	};

}